<template>
  <a-sub-menu class="subMenu" :key="menuInfo.id">
    <template #icon>
      <img class="subMenu-img" v-if="menuInfo.iconUrl" :src="menuInfo.iconUrl" alt="tutu" />
      <img
        class="subMenu-img"
        v-else-if="menuInfo.iconName"
        :src="require(`@/assets/images/${menuInfo.iconName}`)"
        alt="tutu"
      />
    </template>
    <template #title>{{ menuInfo.name }}</template>
    <div v-for="(item, index) in menuInfo.children" :key="item.id || index">
      <subSideMenu v-if="item.children && item.children.length > 0" :menuInfo="item"></subSideMenu>
      <a-menu-item v-else :key="item.id" @click="goto(item)">
        <template #icon>
          <img class="subMenu-img" v-if="item.iconUrl" :src="item.iconUrl" alt="tutu" />
          <img
            class="subMenu-img"
            v-else-if="item.iconName"
            :src="require(`@/assets/images/${item.iconName}`)"
            alt="tutu"
          />
        </template>
        <span>{{ item.name }}</span>
      </a-menu-item>
    </div>
  </a-sub-menu>
</template>

<script>
import { reactive, toRefs } from "vue";
import { useRouter } from "vue-router";
export default {
  name: "SubSideMenu",
  props: {
    menuInfo: {
      type: Object,
      default: () => {},
    },
  },
  setup(props) {
    const state = reactive({
      menuInfo: props.menuInfo,
    });
    const router = useRouter();
    const goto = (item) => {
      console.log(item);
      if (item.url) {
        router.push(item.url);
      }
    };
    return {
      ...toRefs(state),
      goto,
    };
  },
};
</script>

<style lang="scss" scoped>
.subMenu {
  &-img {
    height: 14px;
  }
}
</style>
